import axios from 'axios'
import Cookie from 'js-cookie'

const request = axios.create({
    timeout: 3000
})


// 请求拦截
request.interceptors.request.use((config) => {
    // 在请求头中 添加tolken
    const token = Cookie.get('token')
    if(token) {
        config.headers.Authorization = token
    }

    return config
})

// 响应拦截
request.interceptors.response.use(config => {
    return config.data
}, (err) => {
    return Promise.reject(err)
})

export default request